//
//  RFMImageView.m
//  RainbowFM
//
//  Created by Kratos on 14/12/16.
//  Copyright (c) 2014年 RB. All rights reserved.
//

#import "RFMImageView.h"

@implementation RFMImageViewItem

@end


@implementation RFMImageView

-(instancetype)init
{
    self = [super initWithFrame:CGRectZero];
    if (self) {
    
    }
    return self;
}

-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self creatContents];
    }
    return self;
}

-(void)creatContents
{
    _imageView = [[UIImageView alloc]initWithFrame:self.bounds];
//    _imageView.contentMode = UIViewContentModeScaleAspectFit;
    _imageView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin |UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
    [self addSubview:_imageView];
    
    _avImageView = [[UIImageView alloc]initWithFrame:CGRectMake((CGRectGetWidth(self.bounds) - 40.f)/2, (CGRectGetHeight(self.bounds) - 40.f)/2, 40.f, 40.f)];
    [_avImageView setImage:[UIImage imageNamed:@"player_btn_play_n"]];
    [_avImageView setHighlightedImage:[UIImage imageNamed:@"player_btn_play_p"]];
    _avImageView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin |UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin;
    [_avImageView setHidden:YES];
    [self addSubview:_avImageView];

}

-(void)setItem:(RFMImageViewItem *)item
{
    _item = item;
    [_imageView sd_setImageWithURL:[NSURL URLWithString:_item ? item.imagePath : @""]];
    self.isAv = _item ? item.isav : NO;
}

-(void)setIsAv:(BOOL)isAv
{
    if (_isAv == isAv) {
        return;
    }
    
    if (_isAv) {
        [_avImageView setHidden:YES];
    }else{
        [_avImageView setHidden:NO];
    }
    
    _isAv = isAv;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
